package code.google.jcontainer.test.inject;

import code.google.jcontainer.AbstractContainer;
import code.google.jcontainer.ContainerFactory;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
 * @create 2009-12-21 16:13:37
 */
public class InjectTestCase {

    private static AbstractContainer simpleContainer;

    @BeforeClass
    public static void setup(){
        // get my simple container by name
        simpleContainer = ContainerFactory.scanPackages("code.google.jcontainer.test").getContainer("SimpleContainer3");
    }

    @Test
    public void testFieldInject() {
        // get the simple component by name
        ComponentA componentA = (ComponentA)simpleContainer.getComponent("ComponentA");
        System.out.println(componentA.getComponentB());
        Assert.assertNotNull(componentA.getComponentB());
    }

    @Test
    public void testMethodInject() {
        // get the simple component by name
        ComponentA componentA = (ComponentA)simpleContainer.getComponent("ComponentA");
        System.out.println(componentA.getComponentB2());
        Assert.assertNotNull(componentA.getComponentB2());
    }

    @Test
    public void testConstantInject() {
        ComponentA componentA = (ComponentA)simpleContainer.getComponent("ComponentA");
        Assert.assertNotNull(componentA.getConstant1());
        Assert.assertTrue(componentA.getConstant2() != 0);
    }
}